package cn.school.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class HelloServlet extends HttpServlet {
    public HelloServlet(){
        System.out.println("Hello Servlet被创建了。。。。。。。。。。。。。。。");
    }
    @Override
    public void init() throws ServletException {
        System.out.println("hello servlet初始化了");
    }

    @Override
    public void destroy() {
        super.destroy();
        System.out.println("hello servlet被销毁了");
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.service(req, resp);
        System.out.println("service方法被调用了。。。。。。。。。。。。。。。。。。");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = response.getWriter();
        writer.print("<html>");
        writer.print("<body>");
        writer.print("<h1>This is a post 提交</h1>");
        writer.print("<h1>白春生是我们排名第二的帅哥！</h1>");
        writer.print("</body>");
        writer.print("</html>");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = response.getWriter();
        writer.print("<html>");
        writer.print("<body>");
        writer.print("<h1>Old liu is the most handsome boy</h1>");
        writer.print("<h1>白春生是我们排名第二的帅哥！</h1>");
        writer.print("</body>");
        writer.print("</html>");
    }
}
